<?php 
class KardexesController extends AppController{
    var $name = 'Kardexes';

    function index(){
        configure::write('debug', 0);
        $this->layout = 'ajax';
        $this->loadModel('Almacen');
        $this->set('almacenes', $this->Almacen->find('list',array('conditions'=>array('organizacion_id'=>1))));
    }
    
    function getKardex(){
        configure::write('debug', 0);
        $this->layout = 'ajax';
        $this->loadModel('Kardex');
        $respuesta = $this->Kardex->getDatosArticulo($this->data);
        $this->set('data',$this->data);
        $this->set('stockAnterior',$respuesta['stockAnterior']);
        $this->set('kardexes',$respuesta['principal']);
    }
    
    function getPdf(){
        configure::write('debug', 0);
        $this->layout = 'pdf'; //this will use the pdf.ctp layout
        $this->loadModel('Kardex');
        $respuesta = $this->Kardex->getDatosArticulo($this->data);
        if(!empty($this->data['Articulo']['almacen_id'])){
            $this->loadModel('Almacen');
            $almacen = $this->Almacen->findById($this->data['Articulo']['almacen_id']);
            $this->data['Articulo']['almacen'] = $almacen['Almacen']['descripcion'];
        }else{
            $this->data['Articulo']['almacen'] = 'Todos los almacenes';
        }
        $this->set('data',$this->data);
        $this->set('stockAnterior',$respuesta['stockAnterior']);
        $this->set('kardexes',$respuesta['principal']);
    }
}